package com.lovo.project2.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lovo.project2.bean.StockBean;
import com.lovo.project2.mapper.ICartBeanMapper;
import com.lovo.project2.mapper.IStockBeanMapper;
import com.lovo.project2.service.IStockBeanService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class StockBeanServiceImpl extends ServiceImpl<IStockBeanMapper, StockBean> implements IStockBeanService {
    @Override
    public IPage<StockBean> queryAllList(IPage iPage, String name, int staNumber, int entNumber, String sqlPrice, int type) {
        QueryWrapper queryWrapper = new QueryWrapper();
        if (name != null && !"".equals(name)) {
            queryWrapper.like("goods_name", name);
        }
        if (staNumber != 0) {
            queryWrapper.ge("nub", staNumber);
        }
        if (entNumber != 0) {
            queryWrapper.le("nub", entNumber);
        }
        if (sqlPrice !=null&&!"".equals(sqlPrice)) {
            queryWrapper.eq("sal_price", 0);
        }
        if (type !=0) {
            queryWrapper.eq("goods_type", type);
        }

        return baseMapper.selectPage(iPage, queryWrapper);
    }


    @Override
    public StockBean queryStockBeanById(int id) {
        return baseMapper.selectById(id);
    }

    @Override
    public void updateStockBeanSalPrice(int id, double newSalPrice) {

        StockBean stockBean = new StockBean();
        stockBean.setId(id);
        stockBean.setSalPrice(newSalPrice);
        baseMapper.updateById(stockBean);
    }

    @Override
    public void addStockBean(StockBean stockBean) {
        baseMapper.insert(stockBean);
    }

    @Override
    public boolean reduceNum(String goodsNumb, int num) {
        return false;
    }
}
